package com.tiancheng.trade.payment.channel.umsshop;

import com.tiancheng.trade.commom.core.exception.error.BusinessErrorInfoEnum;
import com.tiancheng.trade.payment.channel.umsmop.UmsMopProperties;
import com.tiancheng.trade.payment.configuration.PayChannelAllConfigs;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * 银联商务新购物车
 *
 * @author kellen
 * @date 2024/11/5
 */
@Component
public class UmsShopAllConfig {
    @Resource
    private PayChannelAllConfigs payChannelAllConfigs;

    public UmsShopProperties getByOrgPayChannelId(Long orgPayChannelId){
        BusinessErrorInfoEnum.CHANNEL_PAY_FAIL.assertIsTrue(null!=orgPayChannelId && CollectionUtils.isNotEmpty(payChannelAllConfigs.getUmsShop()));
        final Optional<UmsShopProperties> first = payChannelAllConfigs.getUmsShop().stream().filter(u -> u.getOrgPayChannelId().equals(orgPayChannelId)).findFirst();
        BusinessErrorInfoEnum.CHANNEL_PAY_FAIL.assertIsTrue(first.isPresent());
        return first.get();
    };
}
